using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Windows;
using System.Xml;
using System.Threading;
using CookComputing.XmlRpc;

namespace uchomeDesktop
{
    class Auth
    {
        public static Boolean login(string uname, string pwd)
        {
            // TODO: use muti-thread to POST remote server
            try
            {
                uchomeAPI uchome = XmlRpcProxyGen.Create<uchomeAPI>();
                uchome.Url = Properties.Settings.Default.uchApiUrl;

                RequestResponseLogger dumper = new RequestResponseLogger();
                dumper.Directory = "C:/temp";
                dumper.Attach(uchome);

                uchome.Url = "http://10.0.1.39/~manyou_branch_v20090414/uchome/api/xmlrpc.php";
                loginResponse ret = uchome.login(uname, pwd);
                Properties.Settings.Default.auth = ret.auth;
                Properties.Settings.Default.uid = ret.uid;
                Properties.Settings.Default.uname = ret.loginuser;

                return true;
            }
            catch
            {
                return false;
            }
        }

        public static void logout()
        {
            Properties.Settings.Default.auth = string.Empty;
            Properties.Settings.Default.uid = string.Empty;
            Properties.Settings.Default.uname = string.Empty;
        }

    }
}
